package com.scs.application.modules.fsd.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.fsd.entity.FsdGroupRole;
import com.scs.application.modules.fsd.service.GroupRoleService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 */
@RestController
@RequestMapping("/back_front/groups_roles")
public class GroupsRolesController  extends CrudController<GroupRoleService, FsdGroupRole> {

    @GetMapping(value = "/getGroupsByRoleService")
    public RestResult getGroupsByRole(@RequestParam("id") String id) {
        return RestResult.ok("获取该权限中的用户群成功", service.getGroupsByRole(id));
    }

    @GetMapping(value = "/getRolesByGroupService")
    public RestResult getRolesByGroup(@RequestParam("id") String id) {
        return RestResult.ok("获取该用户群中的权限成功", service.getRolesByGroup(id));
    }

    @PostMapping(value = "/changeGroupsByRoleService")
    public RestResult changeGroupsByRole(@RequestBody Map<String, String> map) {
        if (service.changeGroupsByRole(StringUtils.stringArryExtract(map.get("idAry"), "groupId"), map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }

    @PostMapping(value = "/changeRolesByGroupService")
    public RestResult changeRolesByGroup(@RequestBody Map<String, String> map) {
        if (service.changeRolesByGroup(StringUtils.stringArryExtract(map.get("idAry"), "roleId"), map.get("id")))
            return RestResult.ok("保存成功！");
        return RestResult.error("保存失败！");
    }
}
